const User_img = require('../../model/User_Img')
const User = require('../../model/User')
module.exports = async (req, res) => {
    // 页码
    let pagenum = Number(req.query.pagenum) || 1
    // 显示条数
    let pagesize = Number(req.query.pagesize) || 5
    let key = req.query.key
    if (!key) {
        res.sendResult(null, 400, '请传递 key')
        return
    }
    const findKey = await User.findOne({ where: { key } })
    if (!findKey) {
        res.sendResult(null, 400, 'key 不存在！')
        return
    }
    // 查询
    const data = await User_img.findAndCountAll({
        where: {
            user_id: findKey.id
        },
        attributes: { exclude: ['user_id'] },
        // 页码
        offset: (pagenum - 1) * pagesize,
        // 显示条数
        limit: pagesize
    })
    // 判断数据是否为空
    if (data.rows.length == 0) {
        res.sendResult(null, 400, '当前页码没有数据！')
        return
    }
    res.sendResult({
        total: data.count,
        file: data.rows
    }, 200, '获取成功！')



}
